package handle

import (
	"context"
	pb "week2zk-project/rpc/api/goods"
	"week2zk-project/rpc/internal/model"
)

func (s *GoodsInfoService) CreateOrder(ctx context.Context, req *pb.CreateOrderRequest) (*pb.CreateOrderResponse, error) {
	o := model.Order{
		UserId:     int(req.UserId),
		GoodsId:    int(req.GoodsId),
		GoodsTitle: req.GoodsTitle,
		GoodsPrice: req.GoodsPrice,
		Num:        req.Num,
		SumPrice:   req.SumPrice,
	}
	err := o.Create()
	if err != nil {
		return &pb.CreateOrderResponse{
			Code: 400,
			Msg:  "创建商品失败",
		}, err
	}
	return &pb.CreateOrderResponse{
		Code:    200,
		Msg:     "创建商品成功",
		OrderId: int64(o.ID),
	}, nil
}
